package com.jason.exp.web;

import org.apache.commons.lang3.StringEscapeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.vdurmont.emoji.EmojiParser;

@Controller
public class HelloController {

	final Logger logger = LoggerFactory.getLogger(HelloController.class);

	@RequestMapping(name = "/hello", method = RequestMethod.GET)
	public String hello() {
		return "hello";
	}

	@RequestMapping(name = "/hello", method = RequestMethod.POST)
	public String doHello(@RequestParam(name = "name", required = true) String name, Model model) {
		logger.debug("Name : {}", name);
		String _name = StringEscapeUtils.escapeJava(name);
		logger.debug("Unicode : {}", _name);
		String emojiUnicode = EmojiParser.parseToUnicode(_name);
		logger.debug("Emoji Unicode : {}", emojiUnicode);
		String emojiAliases = EmojiParser.parseToAliases(name);
		logger.debug("Emoji Aliases : {}", emojiAliases);
		String emojiHtmlDecimal = EmojiParser.parseToHtmlDecimal(name);
		logger.debug("Emoji Html Decimal : {}", emojiHtmlDecimal);
		model.addAttribute("name", name);
		model.addAttribute("_name", _name);
		model.addAttribute("emojiUnicode", emojiUnicode);
		model.addAttribute("emojiAliases", emojiAliases);
		model.addAttribute("emojiHtmlDecimal", emojiHtmlDecimal);
		return "hello";
	}

}
